Field of the Invention
The present invention relates to an image processing method, an image processing apparatus, a program, and a recording medium, and the invention particularly relates to template matching in which a template image including a feature image such as contour information is used.
Description of the Related Art
Processing of finding an object from a picked-up image is one of functions often used in a machine vision. Template matching has been accordingly proposed as image processing for searching for a pattern from the pickup image in general. In the template matching, a feature of a pattern intended to be searched for is prepared as a template image in advance. In a case where the pattern is then searched for from the pickup image, the previously prepared template image is compared with a target image obtained by extracting the feature from the pickup image. Contour information is used in many cases as the feature included in the template image and the target image.
When a direct search for a high resolution image is performed, a problem occurs that it takes much processing time, and a coarse-to-fine search method has been proposed in general as a method for solving the problem. According to the coarse-to-fine search method, a course search is performed first by using a low resolution image, and a fine search is then performed by gradually increasing the resolution. A data structure called pyramid in which a plurality of images having different resolutions are hierarchized is used in the coarse-to-fine search method. This is the data structure in which a low resolution conversion of a pattern feature (for example, a contour) is repeatedly performed, and the pattern features having multiple resolutions are arranged in a layer structure.
The number of images having different resolutions are referred to as number of stages, or levels, of the pyramid. According to this data structure, the top stage of the pyramid is the pattern feature having the lowest resolution, and the resolution is increased as the pyramid stage is lowered. In the actual search, the search is started from the top stage of the pyramid, and the following processing is repeatedly performed in which a result (candidate point) that has been obtained by performing the search in a certain pyramid stage, is searched for at a higher accuracy in a next pyramid stage below.
A related art regarding the coarse-to-fine search method is disclosed, for example, in Japanese Patent Laid-Open No. 2007-257601. Japanese Patent Laid-Open No. 2007-257601 discloses a method of performing a highly accurate search by carrying out the search with use of a pyramid of a previously prepared template image and a pyramid generated from a search target image while the resolution is consecutively increased from the image having the low resolution in the pyramid.
However, according to the coarse-to-fine search method described above in Japanese Patent Laid-Open No. 2007-257601, the pyramid is generated with the previously determined number of stages irrespective of a size of the contour included in the template image. Therefore, the contour may collapse in the template image depending on a search target, and a noise image is generated in some cases. If the noise image is included in the template image, a correct answer may be missed in the search in an intermediate stage of the pyramid, and a search accuracy is degraded.